package cn.com.shopec.erp.provideinterface.commo;

import java.io.UnsupportedEncodingException;

import org.apache.log4j.Logger;

/**
 * 
 * @author yangpinggui 2010-06-01
 * 
 */
public class HttpRequest {

    private static final Logger log = Logger.getLogger(HttpRequest.class);

    private String strHttpUrl = "";
    private String strParameter = null;
    private int threadNum = 0;

    public HttpRequest() {
    }

    public String getHttpUrl() {
        return this.strHttpUrl;
    }

    public void setHttpUrl(String strURL) {
        this.strHttpUrl = strURL;
    }

    public String getParameter() {
        return this.strParameter;
    }

    public void setParameter(String strParameter) {
        this.strParameter = strParameter;
    }

    public int getThreadNum() {
        return this.threadNum;
    }

    public void setThreadNum(int iNum) {
        this.threadNum = iNum;
    }

    /**
     * http send interface
     */
    public String httpSend() {
        String strResult = null;

        try {
            HTTPConnect httpReq = new HTTPConnect(this.strHttpUrl);
            httpReq.setEncoding("UTF-8");
            httpReq.setContentType("text/xml");
            strResult = httpReq.request(this.strParameter);
            strResult = strResult.trim();

            System.out.println(strResult);
        } catch (Exception ex) {
            log.error("httpSend Exception :", ex);
            return "";
        }

        return strResult;
    }

    public static void main(String[] args) throws UnsupportedEncodingException {

        HttpRequest httpRequest = new HttpRequest();
        httpRequest.setHttpUrl("http://gwall.3322.org:9999/Gwms_sp/service/goodsCreateOrUpadte?");
        httpRequest
                .setParameter("appkey=ERP&appsecret=1234567890&format=JSON&data={'brandCode':'2e14da5268ad4c6386dbf6630b90527c','detail':[{'brcode':'12345671','sku':'122000124506','standard':'三星I9268黑色  ','state':'Y'},{'brcode':'12345672','sku':'122000117674','standard':'三星I9268白色  ','state':'Y'},{'brcode':'12345673','sku':'122000120674','standard':'三星I9268白色  ','state':'Y'}],'goodsCode':'f4ee372aa2ce438c9791f5da87e60094','goodsName':'三星I9268','goodsType':'01'}");
        httpRequest.httpSend();

    }

}
